import Vue from 'vue'
import Vuex from 'vuex'
import home from '@/store/modules/home.js'
import mine from '@/store/modules/mine.js'
import persistedState from 'vuex-persistedstate'

Vue.use(Vuex)  // 全局注入一个插件

const vuexPersisted = new persistedState({
  storage: {
    getItem: key => uni.getStorageSync(key),
    setItem: (key, value) => uni.setStorageSync(key, value),
    removeItem: key => uni.clearStorageSync(key)
  }
})

const store = new Vuex.Store({
  modules: {
    home,
    mine
  },
  plugins: [vuexPersisted]
})

export default store